local blaze = require "blaze"
local app = require "app"
local gamelib = require "club.threecard.gamelib"
local game = app.game.running

local M = gamelib.ui.element()

M.store_watchers = {
    machine = {
        ["更新免费次数"] = function(self, store, state, args, isInitialize)
            self.times_txt.text = state.free_times
        end,
    }
}

function M:ctor(context, systems)
    self.systems = systems
    self.res = "club.threecard.slotlib/ui/common.b:freespin"
    self.last_value = 0
end

function M:on_injected(bind)
    bind("button.click", self.btn_launch, self.launch_ivk)
end

function M:launch_ivk()
    if self.systems.current then
        self.systems.current:skip()
        return
    end

    local amount = game.store.machine.getters.bet_value
    self.systems:cleanup()
    local player = blaze.kbe.player()
    if player and player.spin then
        player:spin(amount)
    end
    self.systems:execute()
end

function M:update_value(value)
    gamelib.utility.digit(self.win_txt, self.last_value, value)
    self.last_value = value
end


return M